package com.slicktechnologies.client.views.servicetype;

import javax.swing.ButtonGroup;

import com.google.gwt.user.client.ui.*;
import com.google.gwt.user.datepicker.client.DateBox;
import com.simplesoftwares.client.library.*;
import com.simplesoftwares.client.library.FlexForm.FormStyle;
import com.simplesoftwares.client.library.appskeleton.*;
import com.simplesoftwares.client.library.appstructure.formtablescreen.*;
import com.simplesoftwares.client.library.composite.*;
import com.simplesoftwares.client.library.mywidgets.*;
import com.simplesoftwares.client.library.libservice.*;
import com.slicktechnologies.client.utility.*;
import com.simplesoftwares.client.library.appstructure.*;
import com.slicktechnologies.shared.*;
import com.slicktechnologies.shared.ServiceType;
import com.slicktechnologies.shared.common.*;
import com.slicktechnologies.shared.common.businessprocesslayer.*;
import com.slicktechnologies.shared.common.businessunitlayer.*;
import com.slicktechnologies.shared.common.personlayer.*;
import com.slicktechnologies.shared.common.productlayer.*;
import com.google.gwt.event.dom.client.ClickHandler;
/**
 * FormTablescreen template.
 */
public class ServiceTypeForm extends FormTableScreen<ServiceType>{

	//***********************************Variable Declaration Starts********************************************//
	//Token to add the varialble declarations
	CheckBox cbStatus;


	
  TextBox typeName;
  TextArea taAckMsg,taDiagmsg,taSucMsg,taUnsucMsg;
  DoubleBox diagPrice;
  
  TextArea taDescription;
//***********************************Variable Declaration Ends********************************************//
	

	//Token to add the concrete presenter class name
	//protected <PresenterClassName> presenter;



	public ServiceTypeForm  (SuperTable<ServiceType> table, int mode,
			boolean captionmode) {
		super(table, mode, captionmode);
		createGui();

	}

	//***********************************Variable Initialization********************************************//
	private void initalizeWidget()
	{

		cbStatus=new CheckBox();
		this.taAckMsg=new TextArea();
		this.taDiagmsg=new TextArea();
		this.taSucMsg=new TextArea();
		this.taUnsucMsg=new TextArea();
		this.taDiagmsg=new TextArea();
		diagPrice=new DoubleBox();
		cbStatus.setValue(true);
		typeName=new TextBox();

	}

	/*
	 * Method template to create the formtable screen
	 */

	@Override
	public void createScreen() {

		//Token to initialize the processlevel menus.
		initalizeWidget();


		this.processlevelBarNames=new String[]{"New","Delete"};

		//////////////////////////////////Form Field Declaration/////////////////////////////////////////////////


		//////////////////////////// Form Field Initialization////////////////////////////////////////////////////
		FormFieldBuilder fbuilder;
		fbuilder = new FormFieldBuilder();
		//Token to initialize formfield
		FormField fgroupingCustomerInformation=fbuilder.setlabel("Service Type Name").widgetType(FieldType.Grouping).setMandatory(false).setColSpan(4).build();
		
		fbuilder = new FormFieldBuilder("* Name",typeName);
		FormField ftbtypename= fbuilder.setMandatory(true).setMandatoryMsg("Service Type Name is mandatory!").setRowSpan(0).setColSpan(0).build();

		fbuilder = new FormFieldBuilder("* Acknowledgement Message",taAckMsg);
		FormField ftaackmsg= fbuilder.setMandatory(true).setMandatoryMsg("Acknowledgement Message is mandatory!").setRowSpan(0).setColSpan(4).build();
		
		fbuilder = new FormFieldBuilder("* SucessFul Message",taSucMsg);
		FormField ftaSucMsg= fbuilder.setMandatory(true).setMandatoryMsg("SucessFul Message is mandatory!").setRowSpan(0).setColSpan(4).build();
		
		fbuilder = new FormFieldBuilder("* Un-SucessFul Message",taUnsucMsg);
		FormField ftaUnSucMsg= fbuilder.setMandatory(true).setMandatoryMsg("Un-SucessFul Message is mandatory!").setRowSpan(0).setColSpan(4).build();
		
		fbuilder = new FormFieldBuilder("* Diagnosis Price",diagPrice);
		FormField fdiagprice= fbuilder.setMandatory(true).setMandatoryMsg("Diagnosis Price is mandatory!").setRowSpan(0).setColSpan(0).build();
		
		fbuilder = new FormFieldBuilder("* Diagnosis Message",taDiagmsg);
		FormField fdiagmsg= fbuilder.setMandatory(true).setMandatoryMsg("Diagnosis Message is mandatory!").setRowSpan(0).setColSpan(4).build();
		
		
		
		fbuilder = new FormFieldBuilder("Status",cbStatus);
        FormField fcbStatus= fbuilder.setMandatory(false).setRowSpan(0).setColSpan(0).build();
        
        
          


		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

		////////////////////////////////Lay Out Making Code///////////////////////////////////////////////////////////////


		FormField[][] formfield = {{fgroupingCustomerInformation},
		{ftbtypename,fdiagprice,fcbStatus},
		{ftaackmsg},
		{fdiagmsg},
		{ftaUnSucMsg},
		{ftaSucMsg},
		
		};


		this.fields=formfield;		
	}

	/**
	 * method template to update the model with token entity name
	 */
	@Override
	public void updateModel(ServiceType model) 
	{

		if(typeName.getValue()!=null)
			model.setTypeName(typeName.getValue());
		if(cbStatus.getValue()!=null)
			model.setStatus(cbStatus.getValue());
		if(taDiagmsg.getValue()!=null)
			model.setDiagnosisMessage(taDiagmsg.getText());
		if(taAckMsg.getValue()!=null)
			model.setAcknowledgementMessage(taAckMsg.getValue());
		if(taSucMsg.getValue()!=null)
			model.setSuccessFulMessage(taSucMsg.getValue());
		if(taUnsucMsg.getValue()!=null)
			model.setUnsucessFullMessage(taUnsucMsg.getValue());
		if(diagPrice.getValue()!=null)
			model.setDiagnosisAmount(diagPrice.getValue());
		presenter.setModel(model);


	}

	/**
	 * method template to update the view with token entity name
	 */
	@Override
	public void updateView(ServiceType view) 
	{


		if(view.getTypeName()!=null)
			typeName.setValue(view.getTypeName());
	
			cbStatus.setValue(view.getStatus());
		if(view.getDiagnosisMessage()!=null)
			taDiagmsg.setValue(view.getDiagnosisMessage());
		if(view.getAcknowledgementMessage()!=null)
			taAckMsg.setValue(view.getAcknowledgementMessage());
		if(view.getUnsucessFullMessage()!=null)
			taUnsucMsg.setValue(view.getUnsucessFullMessage());
		if(view.getSuccessFulMessage()!=null)
			taSucMsg.setValue(view.getSuccessFulMessage());
		if(view.getDiagnosisAmount()!=null)
			diagPrice.setValue(view.getDiagnosisAmount());

		presenter.setModel(view);

	}

	/**
	 * Toggles the app header bar menus as per screen state
	 */

	public void toggleAppHeaderBarMenu() {
		if(AppMemory.getAppMemory().currentState==ScreeenState.NEW)
		{
			InlineLabel[] menus=AppMemory.getAppMemory().skeleton.getMenuLabels();
			for(int k=0;k<menus.length;k++)
			{
				String text=menus[k].getText();
				if(text.equals("Save")||text.equals("Discard"))
				{
					menus[k].setVisible(true); 
				}
				else
					menus[k].setVisible(false);  		   

			}
		}

		else if(AppMemory.getAppMemory().currentState==ScreeenState.EDIT)
		{
			InlineLabel[] menus=AppMemory.getAppMemory().skeleton.getMenuLabels();
			for(int k=0;k<menus.length;k++)
			{
				String text=menus[k].getText();
				if(text.equals("Save")||text.equals("Discard"))
					menus[k].setVisible(true); 

				else
					menus[k].setVisible(false);  		   
			}
		}

		else if(AppMemory.getAppMemory().currentState==ScreeenState.VIEW)
		{
			InlineLabel[] menus=AppMemory.getAppMemory().skeleton.getMenuLabels();
			for(int k=0;k<menus.length;k++)
			{
				String text=menus[k].getText();
				if(text.equals("Discard")||text.equals("Edit"))
					menus[k].setVisible(true); 

				else
					menus[k].setVisible(false);  		   
			}
		}
		
	}

	/**
	 * sets the id textbox with the passed count value. 
	 */
	@Override
	public void setCount(int count)
	{


	}

	@Override
	public void clear() {
		// TODO Auto-generated method stub
		super.clear();
		this.cbStatus.setValue(true);
	}

	
	@Override
	public void setEnable(boolean state) {
		super.setEnable(state);
	}




}

